<div class="content">
	<div class="list_button">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
        <tr>
            <td>
                <?php
					echo CHtml::link(
						"<div class='button'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-plus.png") .
							"</div>" .
							"<div style='float:left; width:65px;'>".
								"Thêm mới" .
							"</div>" .
						"</div>"
						,
                       array($this->controller_id."/add",
					   			"page"=> $page)
                    );
					
					echo "<div class='button' id='delete_multi'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-remove.png") .
							"</div>" .
							"<div style='float:left; width:30px;'>".
								"Xóa" .
							"</div>" .
						"</div>";
                ?>
                
                <script language="javascript">
                $(document).ready(function(){
                    $('#delete_multi').click(function(){
                        var form = document.getElementById("form_table_all");
                        form.submit();
                    });	
                })
                </script>
              
            </td>
          </tr>
        </table>
	</div>
   

        <table class="view">
            <tr height='25'>
            	<th width="50px"> # </th>
                <th width="10">
					<?php 
						echo CHtml::checkBox("checkbox_all", false, array("id"=>"checkbox_all"));
					?>
                </th>
            	<th colspan="2" width="10">Action</th>
                <th>Slide Show</th>
                <th width="70">Bật/Tắt</th>
                <th width="100">
               		<?php 
                        echo CHtml::link(
                            "Thứ tự",
                            array($this->controller_id."/set_order","page"=>$page),
                            array("title"=>"Tạo thứ tự mặc định")
                        );
                        echo " ";
                        echo CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-saveorder.png", "", 
                            array("style"=>"cursor:pointer", "id"=>"id_save_order"));
    
                    ?>
                </th>
                <th width="250">URL</th>
                <th width="60">ID</th>
            </tr>
            <?php
                if (! is_null($rows))
                {
					echo CHtml::beginForm(array($this->controller_id."/delete_multi", 
						"page" => $page),
						"post",
						array("id"=>"form_table_all")
					);
					
						$i = 1;
	
						foreach($rows as $row)
						{
							show_row($row, $page, $this->controller_id, $i );
							$i++;
						}
					echo CHtml::endForm();
                }
				
				function show_row($row, $page, $controller_id, $i)
				{
					 echo "<tr>";
						echo "<td align='center'>";
							echo $i;
						echo "</td>";
						
						echo "<td>";
							echo CHtml::checkBox("cib[".$row["id"]."]", false, array("id"=>"cb".$i));
						echo "</td>";
						
						echo "<td width='26px' align='center'>";
							$url = Yii::app()->createUrl(
								"content/" . $controller_id. "/delete",
								array(
									"slideshow_id" => $row->id,
									"page" => $page
								)
							);
							echo CHtml::image(
								Yii::app()->baseUrl.'/assets/icon/icon-16-trash.png',
								"",
								array(
									"style"=>"cursor:pointer",
									"title"=>"Delete",  
									"onClick"=>"javascript:actionDelete('".$url."');"
								)
							);
						echo "</td>";
						
						echo "<td width='26px' align='center'>";
						
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl.'/assets/icon/icon-16-edit.png'),
								array(
									$controller_id."/edit",
									"slideshow_id"=>$row["id"],
									"page" => $page
								),
								array('title'=>'Edit')
							);
							
						echo "</td>";
						
						echo "<td>";
							echo CHtml::link(
								$row["name"],
								array(
									$controller_id."/edit",
									"slideshow_id" => $row["id"],
									"page" => $page
								),
								array('title'=>'Edit')
							);
						echo "</td>";
						
						echo "<td align='center'>";
							$icons =  array(
								0 => "icon-16-remove.png",
								1 => "icon-16-tick.png",
							);
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl.'/assets/icon/'.$icons[$row["enable"]]),
								array($controller_id."/enable", 
									"slideshow_id"=>$row["id"], 
									"page" => $page
								)
							);
						echo "</td>";
						
						
						echo "<td align='right'>";
							echo CHtml::textField(
								"order[".$row->id."]",
								$row->order,
								array("style"=>"width:40px; text-align:right; 
									padding:3px; color:#f00; font-size:11px;")
							);
							echo " ";
							
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-uparrow.png"),
								array(
									strtolower($controller_id."/up"),
									'slideshow_id' => $row["id"],
								),
								array('title'=>'Up')
							);
							
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-downarrow.png"),
								array(
									strtolower($controller_id."/down"),
									'slideshow_id' => $row["id"],
								),
								array('title'=>'Down')
							);
							
						echo "</td>";
						
						echo "<td>";
							
						echo "</td>";
			
						echo "<td align='center'>";
							echo $row["id"];
						echo "</td>";
					echo "</tr>";  	
				}
            ?>
        </table>
    </div>
</div><!-- end div content -->

<?php 
	// display pagination
	if ($pages->pageCount > 1)
	{
		echo "<div class='pagination'>";
			$this->widget('CLinkPager', array(
				'header' => "",
				'cssFile' => Yii::app()->baseUrl."/assets/css/pager.css",
				"prevPageLabel" => "«",
				"nextPageLabel" => "»",
				'pages' => $pages,
			));
			
			$this->widget('CListPager', array(
				//"promptText" => "Chuyển nhanh",
				"header" => "Trang ",
				'pages'=>$pages
			));
		echo "</div>";
	}
?>

<script language="javascript">
function actionDelete(url)
{	
	if (confirm("Bạn muốn xóa mẫu tin này ?") == true)
		window.location = url;
}

</script>

<script language="javascript">
	$(document).ready(function(){
		$('#id_save_order').click(function() {
			var url = '<?php 
				$url = Yii::app()->createUrl(
					$this->route."/save_order",
					array("page"=>$page)
				);
				echo $url;
			?>';
			var form = document.getElementById("form_table_all");
			form.action = url;
			//alert(form.action);
			form.submit();
		});
	});
</script>
